

let vm = new Vue({
    el:'#app',
    data:{
        goods:[
          {id:1,name:'iphone12',price:8765,count:1,time:new Date()},  
          {id:2,name:'iphone8',price:7765,count:2,time:new Date()},  
          {id:3,name:'iphone6',price:6765,count:3,time:new Date()},  
          {id:4,name:'iphone4',price:5765,count:4,time:new Date()},  
          {id:5,name:'iphoneX',price:4765,count:5,time:new Date()}  
        ],
        goodID:null,
        goodName:null,
        key:''
    },
    methods: {
        add(){
          let id = this.goods[this.goods.length-1].id+1
          this.goods.push({
              id:id,
              name:this.goodName,
              time:new Date(),
              count:1,
              price:5000
          }) 
        //   添加完成 后，清空输入框的值 
          this.goodName=null
        },
        remove(index){
            this.goods.splice(index,1)
        },
        decreame(item){
            item.count--
        },
        increame(item){
            item.count++
        } 
    },
    filters:{
      moenyFlag(text){
        //   console.log(typeof text);
        return "￥"+text.toFixed(2)

      }
    },
    computed: {
        search(){
            return this.goods.filter((item)=>{
                return item.name.includes(this.key)
            })
        },
        totalPrice(){
            let total =0
            this.goods.forEach((item)=>{
                total+= item.price * item.count
            })
            return total
        }
    },
})